package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Report;
import cn.wolfcode.crm.query.ReportQueryObject;
import cn.wolfcode.crm.service.IReportService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("report")
public class ReportController {

    @Autowired
    private IReportService reportService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"report:view","报案表页面"},logical = Logical.OR)
    public String view() throws Exception{

        return "report/report";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Report> selectAll() throws Exception{
        return reportService.selectAll();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value = {"report:saveOrUpdate","报案表新增/修改"},logical = Logical.OR)
    public JsonResult saveOrUpdate(Report entity) throws Exception{
        JsonResult jsonResult = new JsonResult();
        try{
            reportService.saveOrUpdate(entity );
        }catch (Exception e){
            jsonResult.mark("操作失败");
        }
        return jsonResult;
    }

    @RequestMapping("changeState")
    @ResponseBody
    @RequiresPermissions(value = {"report:status","报案表状态修改"},logical = Logical.OR)
    public JsonResult status(Long id) throws Exception{
        JsonResult jsonResult = new JsonResult();
        try{
            reportService.changeState(id);
        }catch (Exception e){
            jsonResult.mark("操作失败");
        }
        return jsonResult;
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ReportQueryObject qo) throws Exception{
        return reportService.query(qo);
    }

}
